﻿
namespace Anycmd.Host
{
    using Anycmd.AC.Infra;
    using Model;
    using System;
    using Util;

    /// <summary>
    /// 界面视图业务实体类型。
    /// </summary>
    public sealed class UIViewState : StateObject<UIViewState>, IUIView, IStateObject
    {
        public static readonly UIViewState Empty = new UIViewState(Guid.Empty)
        {
            _acDomain = EmptyACDomain.SingleInstance,
            _createOn = SystemTime.MinDate,
            _icon = string.Empty,
            _tooltip = string.Empty
        };

        private IACDomain _acDomain;
        private string _tooltip;
        private string _icon;
        private DateTime? _createOn;

        private UIViewState(Guid id) : base(id) { }

        public static UIViewState Create(IACDomain host, UIViewBase view)
        {
            if (view == null)
            {
                throw new ArgumentNullException("view");
            }

            return new UIViewState(view.Id)
            {
                _acDomain = host,
                _tooltip = view.Tooltip,
                _createOn = view.CreateOn,
                _icon = view.Icon,
            };
        }

        public IACDomain ACDomain
        {
            get { return _acDomain; }
        }

        public string Tooltip
        {
            get { return _tooltip; }
        }

        public string Icon
        {
            get { return _icon; }
        }

        public DateTime? CreateOn
        {
            get { return _createOn; }
        }

        protected override bool DoEquals(UIViewState other)
        {
            return Id == other.Id &&
                Tooltip == other.Tooltip &&
                Icon == other.Icon;
        }
    }
}
